/*
 * @Author: zwf 240970521@qq.com
 * @Date: 2023-07-14 22:53:39
 * @LastEditors: zwf 240970521@qq.com
 * @LastEditTime: 2023-08-18 21:28:55
 * @FilePath: /esp32_cmake_test/motor/inc/motor.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#ifndef MOTOR_H
#define MOTOR_H

#include "driver/ledc.h"
#include "AS5600.h"
#include "currentSensing.h"
#include "IQmathLib.h"

#define MOTOR_PHASE_NUM 3

typedef struct
{
    ledc_timer_t timer; /*要使用哪个定时器*/
    int          pin[MOTOR_PHASE_NUM];
    float        vMax; /*电压最大值*/
    int          modbusStartAddr;
    int          pp;
} MotorCfg;

typedef struct MotorDev
{
    void *priv;
    void (*start)(struct MotorDev *);
    void (*stop)(struct MotorDev *);
    void (*registerAmpereSensing)(struct MotorDev *, CurrentSensing *);
    void (*registerSensor)(struct MotorDev *, AS5600Dev *);
    void (*setUq)(struct MotorDev *, _iq24);
    void (*setUd)(struct MotorDev *, _iq24);
    void (*setSpeed)(struct MotorDev *, _iq21);
} MotorDev;

extern int dir;

esp_err_t  MOTOR_create(MotorCfg cfg, MotorDev **dev);
void       MOTOR_deleate(MotorDev *);

#endif
